package com.zg.scf.web;

import com.zg.common.core.R;

import com.zg.common.core.dao.scf.entity.RuleItem;
import com.zg.scf.domain.convert.RuleItemConvert;
import com.zg.scf.domain.req.rule.RuleItemReq;
import com.zg.scf.domain.vo.ConfCompanyItemVo;
import com.zg.scf.service.RuleItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>Description: </p>
 *
 * @author zhanfeng.liang
 * @since 2025/5/22 10:54
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/scf/confCompanyItem")
@Slf4j
@Api(tags = "企业配置项管理")
public class RuleItemController {

    @Autowired
    private RuleItemService confCompanyItemService;

    @Autowired
    private RuleItemConvert convert;

    @PostMapping("/add")
    @ApiOperation(value = "添加项目")
    public R add( @RequestBody @Valid  List<RuleItemReq> list) {
        confCompanyItemService.batchAdd(list);
        return R.success();
    }

    @PostMapping("/listByRuleId")
    @ApiOperation(value = "根据企业规则ID查询")
    public R<List<ConfCompanyItemVo>> listByConfigId(@RequestParam("configId") String configId) {
        List<RuleItem>  list=confCompanyItemService.listByRuleId(configId);
        return R.success(convert.toVoList(list));
    }
}
